package com.easy.query.core.proxy.core.tuple.proxy;

import com.easy.query.core.proxy.PropTypeColumn;
import com.easy.query.core.proxy.SQLSelectAsExpression;
import com.easy.query.core.proxy.columns.types.SQLAnyTypeColumn;
import com.easy.query.core.proxy.core.draft.proxy.AbstractDraftProxy;
import com.easy.query.core.proxy.core.tuple.Tuple2;
import com.easy.query.core.proxy.fetcher.AbstractFetcher;
import com.easy.query.core.util.EasyObjectUtil;

import java.util.Optional;

/**
 * this file automatically generated by easy-query, don't modify it
 * 当前文件是easy-query自动生成的请不要随意修改
 *
 * @author xuejiaming
 */
public class Tuple2Proxy<T1,T2> extends AbstractDraftProxy<Tuple2Proxy<T1,T2>, Tuple2<T1,T2>> {

    private static final Class<Tuple2> entityClass = Tuple2.class;


    public Tuple2Proxy(PropTypeColumn<T1> column1, PropTypeColumn<T2> column2) {
        super(2);
        fetch(0, column1, "value1");
        fetch(1, column2, "value2");
    }

    /**
     * {@link Tuple2#getValue1}
     */
    public SQLAnyTypeColumn<Tuple2Proxy<T1,T2>, T1> value1() {
        return getAnyTypeColumn("value1",EasyObjectUtil.typeCastNullable(Optional.ofNullable(getDraftPropTypes()[0]).map(o->o.getPropertyType()).orElse(null)));
    }

    /**
     * {@link Tuple2#getValue2()}
     */
    public SQLAnyTypeColumn<Tuple2Proxy<T1,T2>, T2> value2() {
        return getAnyTypeColumn("value2",EasyObjectUtil.typeCastNullable(Optional.ofNullable(getDraftPropTypes()[1]).map(o->o.getPropertyType()).orElse(null)));
    }


    @Override
    public Class<Tuple2<T1,T2>> getEntityClass() {
        return EasyObjectUtil.typeCastNullable(entityClass);
    }


    /**
     * 数据库列的简单获取
     *
     * @return
     */
    public Tuple2ProxyFetcher<T1,T2> FETCHER = new Tuple2ProxyFetcher<>(this, null, SQLSelectAsExpression.empty);


    public static class Tuple2ProxyFetcher<TF1,TF2> extends AbstractFetcher<Tuple2Proxy<TF1,TF2>, Tuple2<TF1,TF2>, Tuple2ProxyFetcher<TF1,TF2>> {

        public Tuple2ProxyFetcher(Tuple2Proxy<TF1,TF2> proxy, Tuple2ProxyFetcher<TF1,TF2> prev, SQLSelectAsExpression sqlSelectAsExpression) {
            super(proxy, prev, sqlSelectAsExpression);
        }


        /**
         * {@link Tuple2#getValue1}
         */
        public Tuple2ProxyFetcher<TF1,TF2> value1() {
            return add(getProxy().value1());
        }


        /**
         * {@link Tuple2#getValue2}
         */
        public Tuple2ProxyFetcher<TF1,TF2> value2() {
            return add(getProxy().value2());
        }


        @Override
        protected Tuple2ProxyFetcher<TF1,TF2> createFetcher(
                Tuple2Proxy<TF1,TF2> cp,
                AbstractFetcher<Tuple2Proxy<TF1,TF2>, Tuple2<TF1,TF2>, Tuple2ProxyFetcher<TF1,TF2>> prev,
                SQLSelectAsExpression sqlSelectExpression
        ) {
            return new Tuple2ProxyFetcher<>(cp, this, sqlSelectExpression);
        }
    }

}
